package org.example.demo01;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Digits;
import jakarta.validation.constraints.Size;
import org.hibernate.validator.constraints.CreditCardNumber;
import lombok.Data;

@Data
@Entity
@Table(name = "taco_order")
public class TacoOrder implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private Date placeAt=new Date();

    @NotBlank(message="Delivery name is required")
    private String deliveryName;

    @NotBlank(message="Street is required")
    private String deliveryStreet;

    @NotBlank(message="City is required")
    private String deliveryCity;

    @Size(max = 2, message = "State abbreviation must be 2 letters")
    private String deliveryState;

    @NotBlank(message="Zip code is required")
    @Size(max = 10)
    private String deliveryZip;

//    @CreditCardNumber(message="Not a valid credit card number")
    private String ccNumber;

//    @Pattern(regexp="^(0[1-9]|1[0-2])([\\/])([2-9][0-9])$",
//            message="Must be formatted MM/YY")
    @Size(max = 5,message = "不大于五个字符")
    private String ccExpiration;

//    @Digits(integer=3, fraction=0, message="Invalid CVV")
    @Column(name = "cc_cvv")
    private String ccCVV;

    @OneToMany(mappedBy = "order",cascade = CascadeType.ALL)
    private List<Taco> tacos = new ArrayList<>();

    public void addTaco(Taco taco) {
        this.tacos.add(taco);
    }
}